import * as echarts from 'echarts'

import chinaMapData from '../data/china.json'
//引用前需要注册
echarts.registerMap('china', chinaMapData)

export default function (el: HTMLElement) {
  const echartsInstance = echarts.init(el)
  const setOptions = (options: echarts.EChartsOption) => {
    echartsInstance.setOption(options)
  }
  const updateSize = () => {
    echartsInstance.resize()
  }
  window.addEventListener(`resize`, () => {
    echartsInstance.resize()
  })
  return {
    echartsInstance,
    setOptions,
    updateSize
  }
}
